//
//  APIService+Website.m
//  JiZhuiAn
//
//  Created by roger lin on 16/7/8.
//  Copyright © 2016年 Easy. All rights reserved.
//

#import "APIService+Website.h"

@implementation APIService (Website)

- (RACSignal *)loadTheWebsiteTitleWithBlock:(BmobObjectArrayResultBlock)block
{
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        BmobQuery *bQuery = [BmobQuery queryWithClassName:@"Information"];
        [bQuery includeKey:@"websiteTitle"];
        [bQuery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
            block(array,error);
        }];
        return nil;
    }];
    
}

- (RACSignal *)loadTheWebsiteInfo
{
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        BmobQuery *bQuery = [BmobQuery queryWithClassName:@"Information"];
        [bQuery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
//            block(array,error);
            if (error) {
                [subscriber sendError:error];
            }
            else {
                [subscriber sendNext:array];
                [subscriber sendCompleted];
            }
        }];
        return nil;
    }];
    
}

- (RACSignal *)loadTheContextPictureWithWebsiteTitle:(NSString *)title
{
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        BmobQuery *bQuery = [BmobQuery queryWithClassName:@"Information"];
        [bQuery whereKey:@"websiteTitle" equalTo:title];
        [bQuery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
            if (error) {
                [subscriber sendError:error];
            }
            else {
                [subscriber sendNext:array];
                [subscriber sendCompleted];
            }
        }];
        return nil;
    }];
}

@end
